package J20250330_real;

/**
 * Created with IntelliJ IDEA.
 * Description: 买二赠一
 * User: 王圆豪
 * Date: 2025-04-03
 * Time: 21:23
 */
import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main4 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Integer[] arr = new Integer[n];
        boolean[] vis = new boolean[n];
        for(int i = 0; i < n; i++) arr[i] = scan.nextInt();
        Arrays.sort(arr);
        int mid = arr[n-2]/2;
        int pos = n-1;
        while (pos >= 0 && arr[pos] > mid) {
            pos--;
        }
        long total = 0;
        int r = n-1;
        while(func(vis)){
            int count = 0;
            int min = (int) 1e9;
            while(r >= 0 && count < 2){
                if(!vis[r]){
                    total += arr[r];
                    min = Math.min(arr[r], min);
                    vis[r] = true;
                    count++;
                }
                r--;
            }
            while(pos >= 0){
                if(arr[pos]<=(min/2)&&!vis[pos]){
                    vis[pos] = true;
                    break;
                }
                pos--;
            }
        }
        System.out.println(total);
        scan.close();
    }

    static boolean func(boolean[] vis){
        for (boolean vi : vis) {
            if (!vi) return true;
        }
        return false;
    }
}